<template>
  <div>
		<el-space>
			<el-date-picker
				v-model="params.registDate"
				value-format="YYYY-MM-DD"
				@change="getTableData"></el-date-picker>
		</el-space>
		<el-table style="margin-top: 10px" :data="tableData" border>
			<el-table-column label="患者姓名" prop="name"></el-table-column>
			<el-table-column label="性别" prop="gender"></el-table-column>
			<el-table-column label="年龄" prop="age"></el-table-column>
			<el-table-column label="手机号">
				<template #default="scope">
					<span>{{getPhone(scope.row.phone)}}</span>
				</template>
			</el-table-column>
			<el-table-column label="科室" prop="deptName"></el-table-column>
			<el-table-column label="医生" prop="doctorName"></el-table-column>
			<el-table-column label="挂号费" prop="price">
				<template #default="scope">
					<span>{{scope.row.price / 100}}</span>
				</template>
			</el-table-column>
			<el-table-column label="状态">
				<template #default="scope">
					<span v-if="scope.row.active === 1">已挂号</span>
					<span v-else-if="scope.row.active === 2">已缴费</span>
					<span v-else>已退费</span>
				</template>
			</el-table-column>
			<el-table-column label="操作" width="150px">
				<template #default="scope">
					<template v-if="scope.row.active === 2">
						<el-button
							@click="call(scope.row)"
							size="small"
							plain
							type="primary">叫号</el-button>
						<el-button
							type="success"
							plain
							size="small"
							@click="add(scope.row)">诊断</el-button>
					</template>
				</template>
			</el-table-column>
		</el-table>
	</div>
</template>

<script setup>
import { ref, reactive } from 'vue'
import { get, post } from '@/axios'
import dayjs from 'dayjs'
import { useRegisterStore } from '@/stores'
import router from '@/router'
import { getPhone } from '@/util'
const registerStore = useRegisterStore()
const payContent = ref('')
const tableData = ref([])
const params = reactive({
	registTime: dayjs().format('a') === 'am' ? 0 : 1
})

getTableData()
function getTableData () {
	get('/umsDoctor/getRegisterByDoctorId', params, content => {
		tableData.value = content
		console.dir(content)
	})
}

function call (row) {
	const message = `请手机尾号为${row.phone.substr(7)}的患者${row.name}到${row.deptName}来就诊`
	get('/umsDoctor/call', { message }, content => {})
}
function add(row) {
	registerStore.setRegister(row)
	router.push('/doctor/records/add')
}
</script>

<style scoped lang="scss">
</style>